package b3.widget.home.unlock
{
	import b3.config.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.widget.guide.*;
	
	import flash.display.*;
	import flash.text.*;
	import flash.filters.*;
	
	import com.greensock.*;

	public class UnlockBuildingDialog extends BasicWidget
	{
		private var buildingIndex:int;
		private var imgContainer:Sprite;
		
		public function UnlockBuildingDialog(buildingIndex:int, currentRoofType:int, currentUpgrade:int, oldRoofType:int, oldUpgrade:int)
		{
			super();
			this.buildingIndex = buildingIndex;
			var DialogBgr:Class = ResourceHelper.getInstance().getClassByName("MessageBoxBgr");
			var bgr:Sprite = new DialogBgr();
			bgr.height = 200;
			bgr.scaleX = bgr.scaleY;
			bgr.mouseChildren = false;
			addChild(bgr);
			//标题
			var titleField:TextField = new TextField();
			titleField.selectable = false;
        	titleField.autoSize = TextFieldAutoSize.CENTER;
			titleField.defaultTextFormat = new TextFormat(BFont.fontName, 20, 0xFFFFFF, true);
			titleField.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleField.x = this.width / 2;
			titleField.y = 15;
			titleField.text = "建筑解锁！";
			addChild(titleField);
			//图片
			imgContainer = new Sprite();
			addChild(imgContainer);
			refreshImg(oldRoofType, oldUpgrade);
			TweenLite.delayedCall(1, playCloud);
			TweenLite.delayedCall(1.5, refreshImg, [currentRoofType, currentUpgrade]);
			TweenLite.delayedCall(5, close);
		}
		
		private function playCloud():void
		{
			var MovieCloud:Class = ResourceHelper.getInstance().getClassByName("MovieCloud3");
			var movieCloud:BasicMc = new BasicMc(MovieCloud, 25, false, true);
			movieCloud.x = 50;
			movieCloud.y = 45;
			movieCloud.scaleX = 2.2;
			movieCloud.scaleY = movieCloud.scaleX;
			addChild(movieCloud);
		}
		
		private function refreshImg(roofType:int, upgrade:int):void
		{
			while (imgContainer.numChildren > 0)
				imgContainer.removeChildAt(0);
			var buildingConfig:BuildingConfig = Config.buildingConfigs[buildingIndex];
			var ObjectImage:Class;
			//是否加锁
			if (roofType < 0)
				ObjectImage = ResourceHelper.getInstance().getClassByName("QuestionBox");
			else
				ObjectImage = ResourceHelper.getInstance().getClassByName(buildingConfig.iconImage[roofType]);   
			var img:Sprite = new ObjectImage();
			if (roofType >= 0 && upgrade > 0)
			{
				var UpgradeImage:Class = ResourceHelper.getInstance().getClassByName("Upgrade" + upgrade);
				var upgradeImage:Sprite = new UpgradeImage();
				upgradeImage.x = img.width / 2 + 10;
				upgradeImage.y = img.height - 90;
				img.addChild(upgradeImage);
			}
			img.scaleX = 1.5;
			img.scaleY = img.scaleX;
			img.x = (this.width - img.width) / 2;
			img.y = 175 - img.height;
			imgContainer.addChild(img);
//			new Reflect({mc:imgContainer, alpha:50, ratio:80, distance:8, updateTime:-1, reflectionDropoff:1});
		}
		
	}
}